#include "WProgram.h"
#include "ServoRudder.h"
ServoRudder::ServoRudder(int pin, int neutre, int course, int direction)
{
 if(direction>=0){
 _direction=1;
}
else{
 _direction=-1;
}
 _serv.attach(pin);
 _neutreServo=neutre;
 _angle=_neutreServo;
 _courseServo=course;
 goTo(0);
}

ServoRudder::ServoRudder()
{
}

/**
* This method will be activated by a regulator
*/
void ServoRudder::goTo(float cmd)
{
 cmd*=_direction;
 if(cmd<=_courseServo && cmd>=-_courseServo)
 {
  _angle=_neutreServo+cmd;
  _serv.write(_angle);
 }
 else if(cmd>=0)
 {
   _angle=_neutreServo+_courseServo;
   _serv.write(_angle);
 }
 else if(cmd<0)
  {
   _angle=_neutreServo-_courseServo;
   _serv.write(_angle);
  }
}
